package com.ftg.learnmybatis.interfalcexml;

import com.ftg.learnmybatis.interfalcexml.entity.StudentEntity;
import com.ftg.learnmybatis.interfalcexml.student.Istudent;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Arrays;

/**
 * 学习一下xml 接口开发模式
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/3/14 上午9:43
 */
public class LearnInterfaceXml {

    public static void main(String[] args) {
        SqlSession session = null;
        String mybatisconfig = "mybatis-config.xml";
        try {
            //输入流 Reader 文件读取到 java里面
            Reader reader = Resources.getResourceAsReader(mybatisconfig);
            //工厂构建者类  可以根据图纸造工厂 的
            SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
            // ssfb.build(reader) 建造工厂
            SqlSessionFactory sqlSessionFactory = ssfb.build(reader);
            //生产产品
            session = sqlSessionFactory.openSession();

            //缓存 （大量sql）  找到某一个 映射

            // 更好的面向对象
            Istudent istudent = session.getMapper(Istudent.class);
//            System.out.println(istudent.list());
//            System.out.println(istudent.listForEntity());
//
//            StudentEntity stu = new StudentEntity();
//            stu.setSname("张");
//            stu.setSno("s001");
//            System.out.println(istudent.listForEntityByPara(stu));
//            System.out.println(istudent.listForEntityByPara1(stu,"男"));

//            System.out.println(istudent.listForEntityByParaLike1(null,"男"));
            System.out.println(istudent.listForEntityByParaIn(Arrays.asList("张三","李四")));


        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {
            session.close();
        }
    }

}
